import { LOGIN_VERIFICATION_PATHS, TOKEN_SECRET } from "../config"
import jwt from "koa-jwt"

export const jwToken = () => {
  return jwt({ secret: TOKEN_SECRET }).unless({
    custom: (ctx) => {
      const url = new URL(`${ctx.origin}${ctx.originalUrl}`)
      // 需要验证登录的地址
      return LOGIN_VERIFICATION_PATHS.includes(url.pathname)
    }
  })
}